#ifndef JAKAROBOTDEVICE_H
#define JAKAROBOTDEVICE_H

#include <QObject>
#include "device.h"
#include "JAKAZuRobot.h"
#include <QJsonObject>

class JakaRobotDevice : public Device
{
    Q_OBJECT
public:
    explicit JakaRobotDevice(QObject *parent = nullptr);

    QString GetIP() const;
    void SetIP(const QString &newStrIP);
    int GetPort_() const;
    void SetPort_(int nPort);

    void    SetDigitalOutput(int index,int value);

private:
    JAKAZuRobot         m_robot;
    JointValue          m_joint_pos;

    QString m_strIP;
    int m_nPort;

    bool isInPos(JointValue dest_pos,JointValue cur_pos,double theshold);

public:
    bool    connect(QString strIP = "");
    bool    power(bool bEnabled = true);
    bool    enable(bool bEnabled = true);

    bool    isConnect();
    bool    isPower();
    bool    isEnabled();

signals:
    void strIPChanged();
    void nPortChanged();

public:
    virtual Device* clone(Device* pDevice) override;

    virtual void writeXML(QXmlStreamWriter &writer) override;
    virtual void readFromXML(QXmlStreamReader &reader) override;

    virtual int initDevice() override;
    virtual void writeData(const QVariant &data) override;
    virtual void uninitDevice() override;

    virtual QString getClassName() override;

};

#endif // JAKAROBOTDEVICE_H
